﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO.Ports;
using Modbus.Device;
using System.Net.Sockets; 

namespace modbus
{
    class main
    {
        public static void writeModbus(){
            using (SerialPort port = new SerialPort("COM14"))
            {
                // configure serial port
                port.BaudRate = 115200;
                port.DataBits = 8;
                port.Parity = Parity.None;
                port.StopBits = StopBits.One;
                port.Open();

                // create modbus master
                IModbusSerialMaster master = ModbusSerialMaster.CreateRtu(port);

                byte slaveID = 49;
                ushort startAddress = 40000;
                ushort[] registers = new ushort[] { 1, 2, 3 };

                // write three registers
                master.WriteMultipleRegisters(slaveID, startAddress, registers);
            }

        
        
        
        
        }



    }
}
